package licode.unisop.client.controller;

import licode.unisop.client.service.impl.SopAuthCheck;
import licode.unisop.client.utils.SopException;
import licode.unisop.client.vo.SopAuthPlatform;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author licode
 */
@Component
public abstract class SopBaseController {
    @Resource
    private SopAuthCheck sopAuthCheck;

    @Resource
    protected HttpServletRequest request;

    @Resource
    protected HttpServletResponse response;

    protected SopAuthPlatform getPlatform() {
        return sopAuthCheck.getPlatform(request);
    }

    protected SopAuthPlatform checkPlatform() {
        SopAuthPlatform platform = sopAuthCheck.getPlatform(request);
        if (null == platform || !platform.isValid()) {
            // 平台不可用（在认证中心没有注册）
            SopException.throwBy(403, "无效平台！");
        }
        return platform;
    }
}
